/*
 * Copyright (c) 2010 CCX(China) Co.,Ltd. All Rights Reserved.
 *
 * This software is the confidential and proprietary information of
 * CCX(China) Co.,Ltd. ("Confidential Information").
 * It may not be copied or reproduced in any manner without the express 
 * written permission of CCX(China) Co.,Ltd.
 *
 * Author: zhaosj
 * Date: 2011-3-8 下午01:43:53
 */
package com.array;

import java.io.IOException;

/**
 * @author zhaosj
 *
 */
public class Array {
	
	static int count=0;
    private char[]  symbol={'A','B','C','D','E','F','G','X','Y','Z'} ;
    int [] num={0,1,2,3,4,5,6,7,8,9};
    
    public void  check(){
        //System.out.print("进来了呀");
        //temp1 表示数字ABCDE
        int temp1=num[0]*10000+num[1]*1000+num[2]*100+num[3]*10+num[4];
        //temp2表示数字DFG
        int temp2=num[3]*100+num[5]*10+num[6];
        //temp3表示数字XYZDE
        int temp3=num[7]*10000+num[8]*1000+num[9]*100+num[3]*10+num[4];
        //判断表达式是不是成立
        //System.out.print("进入循环");

        if((temp1+temp2*2)==temp3){
            count++;
            System.out.println(temp1+temp2+temp2);
            System.out.println(temp3);
            System.out.println("第"+count+"种答案");
            print();
        }   
    }
	
        public void print(){
            for(int j=0;j<=9;j++){            
                      //输出ABCDEFGXYZ              
                     System.out.print(symbol[j]+"  ");                      
              }
                  System.out.println();
                      for(int j=0;j<=9;j++){    
                          //输出他们对应的值                      
                          System.out.print(num[j]+"  ");                      
                      }
            System.out.println();
                        System.out.println("        "+num[0]+num[1]+num[2]+num[3]+num[4]);
                  System.out.println("          "+num[3]+num[5]+num[6]);
                  System.out.println("  +       "+num[3]+num[5]+num[6]);
                  System.out.println("        "+num[7]+num[8]+num[9]+num[3]+num[4]);
                     System.out.println();

                  
    }

        
	public void function()throws IOException{
        int i,temp,j;
        do{            
            check();
            
            for(i=9;i>0;i--){
                if(num[i]>num[i-1])
                    break;
            }
            if(i==0)
                break;
            i--;
            for(j=9;j>i;j--){
                if(num[j]>num[i]) break;
            }
            temp= num[j];
            num[j]=num[i];
            num[i]=temp; 
            //下面循环是
            for(int x=i+1,y=9;x<y;x++,y--){
                temp=num[x];
                num[x]=num[y];
                num[y]=temp;
            }            
        }while(true);
    }
   
	
	public static void main(String [] args) throws IOException{
        Array p=new Array();
        p.function();
        
    }   


}
